﻿using System.Windows;
using System.Windows.Controls;

namespace Refract.Views
{
    /// <summary>
    /// Base class for views
    /// </summary>
    /// <remarks>Views implement front-end functionality</remarks>
    public class View : UserControl, IView
    {
        #region Properties

        /// <summary>
        /// Gets or sets the name of the region.
        /// </summary>
        /// <value>The name of the region.</value>
        public string RegionName { get; set; }
        /// <summary>
        /// Gets or sets the content that is contained within a user control.
        /// </summary>
        /// <value></value>
        /// <returns>
        /// The content of the user control.
        /// </returns>
        public new UIElement Content
        {
            get { return base.Content; }
            set { base.Content = value; }
        }

        /// <summary>
        /// Gets or sets the name of the view.
        /// </summary>
        /// <value>The name of the view.</value>
        public string ViewName { get; set; }


        /// <summary>
        /// Gets or sets the model.
        /// </summary>
        /// <value>The model.</value>
        public ViewModel ViewModel { get { return DataContext as ViewModel; } set { DataContext = value; } }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="View"/> class.
        /// </summary>
        public View() { }

        /// <summary>
        /// Initializes a new instance of the <see cref="View"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        public View(ViewModel viewModel)
        {
            ViewModel = viewModel;

        }

        #endregion
        
        #region Public Methods

        /// <summary>
        /// Shows this instance.
        /// </summary>
        public virtual void Show()
        {
            Visibility = Visibility.Visible;            
        }

        /// <summary>
        /// Hides this instance.
        /// </summary>
        public virtual void Hide()
        {
            Visibility = Visibility.Collapsed;            
        }

        #endregion
    }
}
